#include <stdio.h>
#include <sys/eventfd.h>
#include <unistd.h>

int main()
{
    // EFD_CLOEXEC 禁止拷贝  EFD_NONBLOCK 设置为非阻塞
    int efd = eventfd(0,EFD_CLOEXEC | EFD_NONBLOCK);
    if(efd < 0)
    {
        perror("eventfd fail!");
        return;
    }
    //写入一次就增加一次，读取出来直接清0
    uint64_t val = 1;
    write(efd,&val,sizeof(val));
    write(efd,&val,sizeof(val));
    write(efd,&val,sizeof(val));

    uint64_t ret = 0;
    read(efd,&ret,sizeof(ret));
    printf("%d\n", ret);
    return 0;
}